Skip to content

Avoid SelectableGroups deprecation warning#5238

Open
HasanTasdiq wants to merge 3 commits into
open-telemetry:mainfrom
HasanTasdiq:codex/fix-importlib-metadata-selectablegroups-warning
Open

Avoid SelectableGroups deprecation warning#5238
HasanTasdiq wants to merge 3 commits into
open-telemetry:mainfrom
HasanTasdiq:codex/fix-importlib-metadata-selectablegroups-warning

Conversation

@HasanTasdiq
Copy link
Copy Markdown
Contributor

@HasanTasdiq HasanTasdiq commented May 20, 2026

Fixes #5231

Summary

  • Updated the importlib metadata compatibility wrapper to normalize SelectableGroups without using its deprecated dict interface.
  • Added regression coverage that treats DeprecationWarning as an error while converting SelectableGroups.
  • Added the towncrier changelog fragment for this API compatibility fix.

Why

On Python 3.10 and 3.11, importlib.metadata.entry_points() can return SelectableGroups. Calling its dict-like values() emits a DeprecationWarning, which breaks users running with warnings as errors when importing opentelemetry.context.

Testing

  • Ran: python3 -m pytest opentelemetry-api/tests/util/test__importlib_metadata.py - passed
  • Ran: python3 -W error -c 'import opentelemetry.context' - passed\n- Ran: python3 -W error -m pytest opentelemetry-api/tests/util/test__importlib_metadata.py - passed\n- Ran: python3 -m ruff check opentelemetry-api/src/opentelemetry/util/_importlib_metadata.py opentelemetry-api/tests/util/test__importlib_metadata.py - passed\n- Ran: python3 -m py_compile opentelemetry-api/src/opentelemetry/util/_importlib_metadata.py opentelemetry-api/tests/util/test__importlib_metadata.py - passed\n\n## Notes\n- Full tox/precommit not run locally because uv and tox are not installed in this shell.\n

@HasanTasdiq HasanTasdiq marked this pull request as ready for review May 20, 2026 23:05
@HasanTasdiq HasanTasdiq requested a review from a team as a code owner May 20, 2026 23:05
Comment thread opentelemetry-api/src/opentelemetry/util/_importlib_metadata.py Outdated
@xrmx xrmx moved this to Reviewed PRs that need fixes in Python PR digest May 21, 2026
return eps
# Handle Python 3.10 SelectableGroups (dict-like)
return EntryPoints(ep for group_eps in eps.values() for ep in group_eps)
with warnings.catch_warnings():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for going back here - I just realized that this context manager is not thread safe. Just to be extra cautious, it's probably best to go back to calling select on each group like you had previously, but still without the conditional using "hasattr".

Comment thread .changelog/5238.fixed
@@ -0,0 +1 @@
Avoid import-time deprecation warnings on Python 3.10 and 3.11.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add package name here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

Importing opentelemetry.context issues a warning in Python 3.10 and 3.11

3 participants